import requests,json
import os,time
import update_sql as sql
execF = False
curTime = time.strftime("%Y/%m/%d",time.localtime())
bakTime = time.strftime("%Y-%m-%d",time.localtime())
# curTime = "2019-1-2"

def get_btc_price():
    url = "https://blockchain.info/ticker"
    html = requests.get(url)
    prices = json.loads(html.text)

    CNY = prices["CNY"]["15m"]
    return CNY



def price_main():
    global execF
    global curTime
    dateTime = time.strftime("%Y-%m-%d",time.localtime())
    if execF is False:
        # dateTime = time.strftime("%Y-%m-%d",time.localtime())
        daily_btc_price = get_btc_price()
        # prices_dict = read_price()

        # put_price(prices_dict,dateTime,daily_btc_price)

        return (dateTime, daily_btc_price)
        # print(prices_dict,dateTime,daily_btc_price)
        execF = True
    else:
        if dateTime > curTime:
            curTime = dateTime
            execF = False

if __name__ == '__main__':
    # while True:
    date,price = price_main()
    print(type(date))
    print(type(price))
        # time.sleep(5)